package com.cdp.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdp.common.core.domain.entity.SysEfficiencyAgent;
import com.cdp.common.core.domain.entity.SysWaterReducer;
import com.cdp.system.dto.SysEfficiencyAgentDTO;
import com.cdp.system.mapper.SysEfficiencyAgentMapper;
import com.cdp.system.service.ISysEfficiencyAgentService;
import com.cdp.system.vo.IdsVO;
import com.cdp.system.vo.SysEfficiencyAgentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysEfficiencyAgentImpl extends ServiceImpl<SysEfficiencyAgentMapper, SysEfficiencyAgent> implements ISysEfficiencyAgentService {


    @Autowired
    private SysEfficiencyAgentMapper sysEfficiencyAgentMapper;



    @Override
    public List<SysEfficiencyAgent> listefficiencyAgents() {
        List<SysEfficiencyAgent> list = list();
        return list;
    }


    /**
     * 减水剂模糊查询
     *
     * @param
     */
    @Override
    public List<SysEfficiencyAgentVO> listMistedEfficiencyAgents(SysEfficiencyAgentDTO sysEfficiencyAgentDTO) {


      List<SysEfficiencyAgentVO>  sysEfficiencyAgentVOS =sysEfficiencyAgentMapper.listMistedEfficiencyAgents(sysEfficiencyAgentDTO);
        return sysEfficiencyAgentVOS;
    }




    /**
     * 模糊查询增效剂id
     * @param id
     * @return
     */
    @Override
    public IdsVO queryEfficiencyAgentsIdsById(Integer id) {
        LambdaQueryWrapper<SysEfficiencyAgent> wrapper = new LambdaQueryWrapper<>();

        // 如果 id 不为 null，则进行模糊查询；否则查询全部
        if (id != null) {
            wrapper.like(SysEfficiencyAgent::getAgentId, id);
        }

        // 查询结果
        List<SysEfficiencyAgent> sysEfficiencyAgentList = sysEfficiencyAgentMapper.selectList(wrapper);

        // 提取 ID 列表
        List<Integer> agentIds = sysEfficiencyAgentList.stream()
                .map(agent -> agent.getAgentId().intValue()) // 手动转换 Long -> Integer
                .collect(Collectors.toList());

        // 设置到 IdsVO 中
        IdsVO idsVO = new IdsVO();
        idsVO.setIds(agentIds);

        return idsVO;
    }

    @Override
    public List<SysEfficiencyAgent> listeEfficiencyAgent(List<Integer> agentIds) {
        if (agentIds == null || agentIds.isEmpty()) {
            return Collections.emptyList();
        }
        return  sysEfficiencyAgentMapper.listeEfficiencyAgent(agentIds);
    }

}
